package com.dzzw.Servlet.AdminServlet;

import com.dzzw.Dao.AdminDao;
import com.dzzw.Model.Admin;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/View/AdminAddServlet")
public class AdminAddServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;
    private AdminDao adminDao = new AdminDao();

    public AdminAddServlet() {
        super();
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        int admin_id = Integer.parseInt(request.getParameter("admin_id"));
        String admin_actnumber = request.getParameter("admin_actnumber");
        String admin_name = request.getParameter("admin_name");
        String admin_password = request.getParameter("admin_password");
        Admin admin = new Admin(admin_id,admin_actnumber,admin_password,admin_name);
        admin.setAdmin_id(admin_id);
        admin.setAdmin_actnumber(admin_actnumber);
        admin.setAdmin_password(admin_password);
        admin.setAdmin_name(admin_name);
        AdminDao adminDao = new AdminDao();
        adminDao.AdminAdd(admin);
        System.out.println("管理员添加成功！");
        response.sendRedirect("/View/Admin.jsp");
    }
}
